package com.xudow.app.dynamicstate_old.module.message;

import android.support.annotation.LayoutRes;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.utils.JTimeTransform;
import com.jude.utils.JUtils;
import com.squareup.picasso.Picasso;
import com.xudow.app.R;
import com.xudow.app.dynamicstate_old.data.ImageModel;
import com.xudow.app.dynamicstate_old.domain.entity.PushMessage;

import java.text.SimpleDateFormat;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by ske on 2016/6/30.
 */
public class DynamicMsgViewHolder extends BaseViewHolder<PushMessage> {
    @BindView(R.id.avatar)
    CircleImageView avatar;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.photo)
    ImageView photo;
    @BindView(R.id.content)
    TextView content;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.tv_delete)
    TextView delete;

    public DynamicMsgViewHolder(ViewGroup parent) {
        super(parent, R.layout.item_msg);
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(PushMessage data) {
        if (TextUtils.isEmpty(data.getSenderHeadurl()))
            Glide.with(getContext()).load(R.drawable.default_head_img).into(avatar);
        else
            Glide.with(getContext()).load(ImageModel.getXueDouImage(data.getSenderHeadurl())).into(avatar);
        name.setText(data.getSenderName());
        time.setText(new SimpleDateFormat("MM-dd HH:mm").format(data.getSendTime()));
        content.setText(data.getContent());
        if (!TextUtils.isEmpty(data.getDynamicImgPath()))
            Glide.with(getContext()).load(data.getDynamicImgPath()).into(photo);
        delete.setOnClickListener(v -> deleteListener.onDelete(getAdapterPosition(), data.getId()));
    }

    public void setOnDeleteListener(OnDeleteListener deleteListener) {
        this.deleteListener = deleteListener;
    }

    OnDeleteListener deleteListener;

    public interface OnDeleteListener {
        void onDelete(int position, long pid);
    }
}
